package com.bwf.jdbc2;

import java.sql.*;
import java.util.ArrayList;

/**
 * @Version v1.0
 * @Description: TODO
 * @Author ZHANZHONGXIN
 * @Date 2022/6/1 16:33
 * @Copyright 博为峰
 */
public class StudentDaoImpl implements StudentDao {
    @Override
    public ArrayList<Student> list() throws SQLException {
        ArrayList<Student> list = new ArrayList<>();
        Connection connection = DBUtil.getConn();
        PreparedStatement preparedStatement = connection.prepareStatement("select * from t_student");
        ResultSet resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {
            int id = resultSet.getInt("id");
            String name = resultSet.getString("name");
            String sex = resultSet.getString("sex");
            Date birthday = resultSet.getDate("birthday");
            Student student = new Student(name, sex, birthday, 0, null, null, 0);
            list.add(student);
        }
        return list;
    }
}
